﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Text.RegularExpressions;
using DGen;
using DGen.Text;

namespace QuickTest
{
    class Program
    {
        
        static void Main (string[] args)
        {
            Console.WriteLine ("STARTING...");

            var s = DGen.Text.Time.UnixEpochTimeString ();
            Console.WriteLine (s);

            Console.WriteLine("ENDING...");
            

        }


     



    }





/*
 *
            string moo = @"Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System Idle Process              0 Services                   0         24 K
System                           4 Services                   0         44 K
smss.exe                       224 Services                   0         52 K
csrss.exe                      308 Services                   0      1,268 K
wininit.exe                    368 Services                   0        100 K
csrss.exe                      380 Console                    1      6,768 K
services.exe                   448 Services                   0      4,064 K
winlogon.exe                   460 Console                    1        108 K
lsass.exe                      492 Services                   0      3,540 K
lsm.exe                        500 Services                   0      1,008 K
svchost.exe                    632 Services                   0      2,256 K
svchost.exe                    704 Services                   0      2,736 K
Ati2evxx.exe                   756 Services                   0        832 K
svchost.exe                    792 Services                   0      7,704 K";
            string[] array=moo.Split('\n');
            Delimiter d = new Delimiter(true, array);
            

 *
 */




    public class Delimiter
    {
        private string _current;
        private int[,] _fixedWidths;
        public Delimiter(string userDelimiter)
        {
            _current = userDelimiter;
        }
        public Delimiter(char userDelimiter)
        {
            _current = userDelimiter.ToString() ;
        }
        public Delimiter(bool useFixedWidth, string[] inputString)
        {
            ArrayList array = new ArrayList();
            ArrayList array2 = new ArrayList();
            int x, y;
           
            bool wasSpace;
            bool isSpace;
            bool isLetter;
            foreach (string line in inputString)
            {
                x = 0;
                y = 0;
                char[] c = line.Trim().ToCharArray();
                for (int i = 0; i < c.Count(); i++)
                {
                    if (Char.IsWhiteSpace(c[i]))
                    {
                        y = x;
                        x = i;
                        if (x > y + 1) { array.Add(i); }
                    }
                }

                int[] fixedWidths = (int[])array.ToArray(typeof(System.Int32));
                array2.Add(fixedWidths);
            }
            int iCounter = 0;
            foreach (int[] fixedWidthSet in array2)
            {
                int[] fixedWidths = fixedWidthSet;
                string thisLine = "";
                int zz=0;
                foreach (int f in fixedWidths)
                {zz=f-thisLine.Length;
                    thisLine+=DGen.DText.Replicate("_",zz);
                    thisLine+="|";
                }
                Console.WriteLine(iCounter.ToString()+ " " +thisLine);
                iCounter++;
            }
            

        }

    }



    class MPAN
    {

        // PUBLIC FIELDS

        /// <summary>
        /// 13 digit number. This will be based on the users input to the constructor.
        /// </summary>
        public string MPANCore = "";

        /// <summary>
        /// This will be the full 21 digit number if available. Otherwise it will be the MPAN Core.
        /// </summary>
        public string TheMPAN = "";
        /// <summary>
        /// The calculated last digit based on users input.
        /// </summary>
        public int CheckDigit = -1;

        /// <summary>
        /// Is this a valid MPAN?
        /// </summary>
        public bool IsValid = false;
        

        

        // CONSTRUCTOR
        public MPAN(string input)
        {
            inMPAN = input.Trim();
            if (inMPAN.Length == 21)
            {
                MPANCore = inMPAN.Substring(8, 13);
            }
            else
            {
                MPANCore = inMPAN.Substring(0, 13);
            }
            
            int[] primes = { 3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43 };
            int runningTotal = 0;
            char[] mpanArray = inMPAN.ToCharArray();
            for (int i = 0; i < 12; i++)
            {
                char c = mpanArray[i];
                int n = Convert.ToInt16(c.ToString());
                int subtotal = primes[i] * n;
                
                runningTotal += (n * primes[i]);
                //Console.WriteLine("n times prime " + n.ToString() + " * " + primes[i].ToString() + " = " + subtotal.ToString() + "(" + runningTotal.ToString()+ ")");

            }
            RunningTotal = runningTotal;

            int leftOver = runningTotal % 11 % 10;
            CheckDigit = leftOver;
            checkValid();
        }

        //PRIVATE METHODS

        private void checkValid()
        {
            bool isValidMPAN = false;
            string LastCharacter = "";
            if (inMPAN.Length >= 13)
            {
                LastCharacter = inMPAN.Substring(12, 1);
            }
            if (Convert.ToInt16(LastCharacter) == CheckDigit)
            {
                isValidMPAN = true;
            }
            IsValid = isValidMPAN;

        }

        // PRIVATE FIELDS
        private string inMPAN = "";
        private int RunningTotal = 0;

    }




}
